(define-module (verify))

(define-public (honey-pot-check post-data)
  ;; fixme wha does this work? or does it?
  (if (string= "" (car (assoc-ref post-data "hidden")))
      #t
      #f))

(define-public (all-input-has-values post-data)
  (map (lambda (element)
         (let ([name (car element)]
               [value (car (cdr element))])
           (if (equal? "" value)
               #f
               #t)))))
;;this doesn't seem to work
;;(define-public email-regexp make-regexp "^[a-z0-9]+[a-z0-9]+\.[a-z]{2,}$" regexp/icase)
(define-public email-regexp (make-regexp "[a-z0-9]+[a-z0-9]+\\.[a-z]{2,}$" regexp/icase))

(define-public (email-is-valid email)
  (if (not (regexp-exec email-regexp email))
      #f
      #t))

(define-public (verify-body body)
  (let* ([post-data (decode body)]
         [honey-pot? (honey-pot-check post-data)]
         [all-input-has-values? (all-input-has-values
                                 ;; (assoc-remove!   "own-number")
                                 (assoc-remove! post-data "hidden"))]
         [email-is-valid? (email-is-valid (assoc-ref 'hidden post-data))]
         )
    (when email-is-valid?
      (display "email is valid!"))))
